package com.xieyingwangluo.yxpart.api;

import com.alibaba.fastjson.JSON;
import com.xieyingwangluo.yxpart.bean.Result;
import com.xieyingwangluo.yxpart.entity.PartModel;
import com.xieyingwangluo.yxpart.logic.PartLogic;
import com.xieyingwangluo.yxpart.service.PartService;
import com.xieyingwangluo.yxpart.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.Date;
import java.util.List;

@Api(tags = "part接口")
@Controller
@RequestMapping(value = "/api/v1/part")
public class PartBaseRest extends BaseRest {
    @Autowired
    private PartLogic partLogic;
    @Autowired
    private PartService partService;

    //我发布的兼职 (显示兼职列表信息)
    @ApiOperation(value = "显示我发布的兼职", notes = "显示我发布的兼职", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "salary", value = "薪资", required = false, dataType = "itn", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "unit", value = "单位（0小时，1日，2周，3月）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "labour", value = "工作时间", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "setcycle", value = "结算周期", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "hirnumb", value = "招聘人数", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "sex", value = "性别要求", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "content", value = "工作内容", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "start_time", value = "工作开始时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "end_time", value = "工作结束时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "job_address", value = "工作地点", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "兼职状态", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "merchant_id", value = "商户id", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "aaa", value = "按条件排序", required = false, dataType = "Integer", paramType = "query")
    })
    @ResponseBody
    @GetMapping(value = "/selA")
    public Result selA(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       PartModel partModel
    ) {
        System.out.println(JSON.toJSONString(partModel));
        return partLogic.selA(partModel);
    }

    // 添加职位(发布职位):职位,时间,薪资,地点,职位描述
    @ApiOperation(value = "添加职位", notes = "添加职位", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "兼职id", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "salary", value = "薪资", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "兼职类型（0兼职，1全职）", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "unit", value = "单位（0小时，1日，2周，3月）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "labour", value = "工作天数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "create_time", value = "发布时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "setcycle", value = "结算周期（0日结，1周结，2月结）", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "hirnumb", value = "招聘人数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "sex", value = "性别要求", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "content", value = "工作内容", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "times", value = "工作开始时间", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "timee", value = "工作结束时间", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "job_address", value = "工作地点", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "兼职状态（审核通过0，审核未通过1,待审核2,过期3）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "merchant_id", value = "商户id", required = false, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @PostMapping(value = "/add")
    public Result add(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      PartModel partModel, String times, String timee
    ) {
        return partLogic.add(partModel, times, timee);
    }

    //修改兼职状态
    @ApiOperation(value = "修改兼职状态", notes = "修改兼职状态", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "兼职编号UUID", required = true, dataType = "String", paramType = "query", defaultValue = "545344"),
            @ApiImplicitParam(name = "state", value = "兼职状态", required = true, dataType = "int", paramType = "query", defaultValue = "0")
    })
    @ResponseBody
    @PutMapping(value = "/upd")
    public Result upd(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      @RequestParam("noid") String noid,
                      @RequestParam("state") int state
    ) {

        return partLogic.upd(noid, state);
    }

    //批量添加
    @ApiOperation(value = "批量添加职位", notes = "批量添加职位", produces = "application/json")
    @ApiImplicitParams({
    })
    @ResponseBody
    @PutMapping(value = "/addP")
    public Result addP(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       PartModel partModel
    ) {
        File file = new File("C:\\Users\\lx\\Desktop\\兼职数据.xls");
        List<PartModel> list = ExcelUtil.read(file);
        for (PartModel p : list) {
            p.setStart_time(new Date());
            p.setEnd_time(new Date());
            partService.add(p);
        }
        return null;
    }

    //显示兼职 (显示兼职信息)
    @ApiOperation(value = "显示单条兼职信息", notes = "显示单条兼职信息", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "兼职编号", required = true, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @GetMapping(value = "/selO")
    public Result selO(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       String noid
    ) {

        return partLogic.selO(noid);
    }

    //按条件查询兼职信息
    @ApiOperation(value = "按条件查询兼职信息", notes = "按条件查询兼职信息", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "aaa", value = "排序的条件", required = false, dataType = "int", paramType = "query"),
    })
    @ResponseBody
    @GetMapping(value = "/selZ")
    public Result selZ(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       int aaa
    ) {
        return partLogic.selZ(aaa);
    }

}
